AIM : Task #1 - To calculate distance to shore from coastline polygons and estimate such distance at various spatial points. Task #2 - To Calculate/estimate attributes for 17-18 NZ MHW using same methodology as Gupta et al. (2020) and Holbrook et al. (2019). Task #3 - Calculate the length of coastline embedded in MHW polygons (62 + NZ 17/18 created).
Document Note : The maps, plots and app within this document are interactive so make sure you give them a play like zooming in and out in the maps but also on the plots. Clicking on the legend allows to only select and display the time series needed.
Task #1: Calculate distance to shore - World - 10m coastline - UPDATED
Task #2: Calculate/estimate attributes for 17-18 NZ MHW using same methodology as Gupta2020
UPDATED : just use data from NOAA https://data.noaa.gov/dataset/dataset/distance-to-nearest-coastline-0-01-degree-grid2
## Coastline 10m resolution, from https://www.naturalearthdata.com/downloads/10m-physical-vectors/10m-coastline/
#coastline_10 <- ne_coastline(scale = 10, returnclass = "sf")
coastline_10 <- st_read('ne_10m_coastline.shp')
## Reading layer `ne_10m_coastline' from data source `C:\Users\thoralf\Documents\Collab\Mads_MHW_SpatialModelling\ne_10m_coastline.shp' using driver `ESRI Shapefile'
## Simple feature collection with 4133 features and 3 fields
## geometry type: LINESTRING
## dimension: XY
## bbox: xmin: -180 ymin: -85.22194 xmax: 180 ymax: 83.6341
## geographic CRS: WGS 84
##
## Spatial points data, tidying to make sf object
coords <- read_excel('62 extreme mhw boundaries and other events.xlsx',sheet='Event dis-to-coast')
# Need to transform points in coords to actual sf points
coords_noNA <- coords %>% drop_na() #Drop row containing na (only 1)
coords_sf <- st_as_sf(as.data.frame(coords_noNA)[,1:3],coords = c('LONGITUDE','LATITUDE'),crs = crs(coastline_10))
##
##
# Creating a grid/raster with the same extent as zone (to prepare rasterize operation)
# raster_grid_full <- raster(ext=extent(c(-180,180,-90,90)),vals=-999999)
# Use of raster::rasterize() function to create raster with value==1 at coastline, NA otherwise
# I let it as comment as it takes approx 300s on my computer, so I use the saved raster
# coastline_10_ras <- rasterize(coastline_10,raster_grid_full,field=1,background=NA)
# Use of raster::distance() function to calculate min distance between each NA cells to non-NA one (ie coastline)
# I let it as comment as it takes approx 600s on my computer, so I use the saved raster (same as above).
# distance_full_10 <- distance(coastline_10_ras)
#I just load the raster previously calculated for gain of time
distance_full_10 <- raster('DistanceToShore_World_10m.tif')
##
pal <- colorNumeric(rev(heat.colors(100)), c(0,max(values(distance_full_10),na.rm=T)), na.color = "transparent")
m <- leaflet(coastline_10) %>% setView(lng = 160, lat = -35, zoom = 4) %>%
addTiles() %>%# Print the map
addScaleBar(position = "bottomright",options = scaleBarOptions(imperial=F)) %>%
addMouseCoordinates() %>%
addGlPoints(data = coords_sf, group = "pts",popup = coords_sf$`MT ID`) %>%
addRasterImage(distance_full_10,layerId = "Dist", col=pal, opacity = 0.8,project=T,maxBytes=Inf) %>%
addLegend(pal = pal, values = c(0,max(values(distance_full_10),na.rm=T)),title = "Distance to shore (m)") %>%
addPolylines(color = "#444444", weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 0.5,
#fillColor = ~colorQuantile("YlOrRd", Source)(Source),
popup = coastline_10$featurecla,
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE))
## Registered S3 method overwritten by 'jsonify':
## method from
## print.json jsonlite
m